package com.akk.utils;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期处理

 */
public class DateUtils {
	/** 时间格式(yyyy-MM-dd) */
	public final static String DATE_PATTERN = "yyyy-MM-dd";
	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    /**时间格式yyyyMMdd*/
	public final static String DATE_NO_INTERVAL="yyyyMMdd";
    /**时间格式HHmmss*/
    public final static String TIME_NO_INTERVAL="HHmmss";
    /**时间格式yyyyMMddHHmmss*/
    public final static String DATETIME_NO_INTERVAL="yyyyMMddHHmmss";

    public final static String DATE_MONTH = "MM";

    public final static String DATE_DAY = "dd";
    public static String formatGetMonth(Date date){
        return format(date,DATE_MONTH);
    }
    public static String formatGetDay(Date date){
        return format(date,DATE_DAY);
    }
    public static String formatByPatt(Date date, String patt){
        return format(date,patt);
    }
	public static String format(Date date) {
        return format(date, DATE_PATTERN);
    }

    public static String formatDateTimeNoInterval(Date date) {
        return format(date,DATETIME_NO_INTERVAL);
    }
    public static String formatDateNoInterval(Date date) {
        return format(date,DATE_NO_INTERVAL);
    }
    public static String formatTimeNoInterval(Date date) {
        return format(date,TIME_NO_INTERVAL);
    }

    public static String format(Date date, String pattern) {
        if(date != null){
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            return df.format(date);
        }
        return null;
    }
    public static Date toDate(String time){
        SimpleDateFormat sdf=new SimpleDateFormat(DATE_TIME_PATTERN);//小写的mm表示的是分钟
        try {
            Date date=sdf.parse(time);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String getNowDay() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd");

        return sdf.format(new Date());
    }

    @Test
    public void test1() {
        System.out.print(getNowDay());
    }




}
